#!/usr/bin/env python3
# -*- coding: utf-8 -*-

'序列化'

import pickle


class Coder(object):
    def __init__(self, name, type):
        self.name = name
        self.type = type

coder = Coder('毛毛','前端开发工程师')


# print(pickle.dumps(coder)) # b'\x80\x03c__main__\nCoder\nq\x00)\x81q\x01}q\x02(X\x04\x00\x00\x00nameq\x03X\x06\x00\x00\x00\xe6\xaf\x9b\xe6\xaf\x9bq\x04X\x04\x00\x00\x00typeq\x05X\x15\x00\x00\x00\xe5\x89\x8d\xe7\xab\xaf\xe5\xbc\x80\xe5\x8f\x91\xe5\xb7\xa5\xe7\xa8\x8b\xe5\xb8\x88q\x06ub.'

# 序列化到文件
# with open('./test.txt','wb') as f:
#     pickle.dump(coder,f)

# 反序列化
cod = None
with open('./test.txt','rb') as f:
    cod = pickle.load(f)
print(cod.name) # 毛毛